package com.siam.package_rider.controller.rider;

import java.util.List;
import java.util.stream.Collectors;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.siam.package_rider.model.result.TbDeliveryOrderResult;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.siam.package_common.entity.BasicResult;

import com.siam.package_rider.entity.TbDeliveryOrder;
import com.siam.package_rider.service.TbDeliveryOrderService;
import com.siam.package_rider.model.param.TbDeliveryOrderParam;

import javax.validation.Valid;

/**
 * ---------------------------
 * 配送订单表 (TbDeliveryOrderController)         
 * ---------------------------
 * 作者：  高品
 * 时间：  2025-03-29 18:55:18
 * ---------------------------
 */
@RestController
@RequestMapping("/rest/rider/deliveryOrder")
public class TbDeliveryOrderController {

	@Autowired
	private TbDeliveryOrderService tbDeliveryOrderService;


    /**
     * 分页查询代抢订单
     * @param request 骑手经纬度
     * @return
     */    
	@PostMapping(value="/page")
	public BasicResult<Page<TbDeliveryOrderResult>> page(@RequestBody @Validated TbDeliveryOrderParam.DeliveryOrderPageRequest request) {
		Page<TbDeliveryOrderResult> page = tbDeliveryOrderService.page(request);
		return BasicResult.success(page);
	}

	/**
	 * 分页查询骑手请求
	 * @param request
	 * @return
	 */
	@PostMapping(value="/pageRiderOrder")
	public BasicResult<Page<TbDeliveryOrderResult>> pageRiderOrder(
			@RequestBody @Validated TbDeliveryOrderParam.RiderOrderPageRequest request) {
		Page<TbDeliveryOrderResult> page = tbDeliveryOrderService.pageRiderOrder(request);
		return BasicResult.success(page);
	}
	
    /**
     * 根据主键查询骑手订单的详情
     * @param param
     * @return
     */ 	
	@PostMapping(value="/orderDetail")
	public BasicResult<TbDeliveryOrderResult> orderDetail(@RequestBody TbDeliveryOrderParam param) {
		return BasicResult.success(tbDeliveryOrderService.orderDetail(param));
	}


	/**
	 * 骑手抢单
	 * @param request
	 * @return
	 */
	@PostMapping(value = "/grabOrder")
	public BasicResult grabOrder(@RequestBody TbDeliveryOrderParam.GrabOrderRequest request) {
		tbDeliveryOrderService.grabOrder(request);
		return BasicResult.success();
	}

	/**
	 * 骑手转单
	 * @return
	 */
	@PostMapping(value = "/transferOrder")
	public BasicResult transferOrder(@RequestBody TbDeliveryOrderParam param) {
		tbDeliveryOrderService.transferOrder(param);
		return BasicResult.success();
	}

	/**
	 * 骑手拒绝接单
	 * @param param
	 * @return
	 */
	@PostMapping(value = "/refuse")
	public BasicResult refuse(@RequestBody TbDeliveryOrderParam param) {
		tbDeliveryOrderService.refuse(param);
		return BasicResult.success();
	}

	/**
	 * 骑手确认到店
	 * @param param
	 * @return
	 */
	@PostMapping(value = "/confirmToStore")
	public BasicResult confirmToStore(@RequestBody TbDeliveryOrderParam param) {
		tbDeliveryOrderService.confirmToStore(param);
		return BasicResult.success();
	}

	/**
	 * 骑手确认取货
	 * @param param
	 * @return
	 */
	@PostMapping(value = "/confirmPickUp")
	public BasicResult confirmPickUp(@RequestBody TbDeliveryOrderParam param) {
		tbDeliveryOrderService.confirmPickUp(param);
		return BasicResult.success();
	}

	/**
	 * 骑手确认送达
	 * @param param
	 * @return
	 */
	@PostMapping(value = "/confirmDelivery")
	public BasicResult confirmDelivery(@RequestBody TbDeliveryOrderParam param) {
		tbDeliveryOrderService.confirmDelivery(param);
		return BasicResult.success();
	}
}